/*
 * Copyright (c) Zhongkehonglue Technologies Co., Ltd. 2025. All rights reserved.
 * Description: DMC callback module.
 * Author: wangchunyang
 * Create: 2025-05-23
 */

#include "dmcCallback.h"
#include "dmcLog.h"
#include "dmcApiTypes.h"

#ifdef LOG_TAG
#undef LOG_TAG
#endif

namespace DlnaDmc {
DmcCallback DmcCallback::instance;

dmc_int32 DmcCallback::SetCb(const DmcCbType &cb)
{
    std::lock_guard<std::mutex> guard(mtx);
    if (!cb.deviceUpCb || !cb.deviceDownCb) {
        LOGE("cb empty");
        return DMC_CALLBACK_EMPTY;
    }
    this->cb = cb;
    return DMC_SUCCESS;
}

dmc_int32 DmcCallback::ReSetCb()
{
    std::lock_guard<std::mutex> guard(mtx);
    this->cb = {nullptr, nullptr};
    return DMC_SUCCESS;
}

dmc_int32  DmcCallback::ExecDeviceUpCb(UploadDeviceInfo &deviceInfo)
{
    std::lock_guard<std::mutex> guard(mtx);
    if (!cb.deviceUpCb) {
        LOGE("cb empty");
        return DMC_CALLBACK_EMPTY;
    }
    return cb.deviceUpCb(deviceInfo);
}

dmc_int32  DmcCallback::ExecDeviceDownCb(dmc_uint32 deviceId)
{
    std::lock_guard<std::mutex> guard(mtx);
    if (!cb.deviceDownCb) {
        LOGE("cb empty");
        return DMC_CALLBACK_EMPTY;
    }
    return cb.deviceDownCb(deviceId);
}
} // DlnaDmc






